<?php

namespace App\Model\Table;

use Cake\Datasource\ConnectionManager;
use Cake\ORM\Table;
use Cake\Validation\Validator;


class SiteTdkTable extends Table
{

    /**
     * Initialize method
     *
     * @param array $config The configuration for the Table.
     * @return void
     */
    public function initialize(array $config)
    {
        parent::initialize($config);
        $this->setConnection(ConnectionManager::get('seo'));
        $this->setTable('site_tdk');
        $this->setPrimaryKey('id');

    }


    /**
     * Default validation rules.
     *
     * @param \Cake\Validation\Validator $validator Validator instance.
     * @return \Cake\Validation\Validator
     */
    public function validationDefault(Validator $validator)
    {
        $validator
            ->integer('id')
            ->allowEmpty('id', 'create');

        $validator
            ->allowEmpty('host');

        $validator
            ->allowEmpty('path');

        $validator
            ->allowEmpty('title');

        $validator
            ->allowEmpty('keywords');

        $validator
            ->allowEmpty('description');

        $validator
            ->allowEmpty('create_time');

        return $validator;
    }

    protected $host = 'www.zhaokao123.cn';

    public function gettdk($path = '')
    {
        $where = [
            'host' => $this->host,
            'path' => $path
        ];
        $res   = self::find()->where($where)->first();
        if ($res) {
            return $res;
        }else{
            return false;
        }
    }
}

